package com.fjjn.component;

import jakarta.annotation.Resource;
import org.redisson.api.RBucket;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;

import java.time.Duration;

@Component
public class RedisCacheUtils {

    public static final Integer DEFAULT_EXP = 3600;


    @Resource
    private RedissonClient redissonClient;

    public <T> T getKey(String key){
        RBucket<T> bucket = redissonClient.getBucket(key);
        return bucket.get();
    }

    public <T> void put(String key,T value){
        RBucket<T> bucket = redissonClient.getBucket(key);
        bucket.set(value, Duration.ofSeconds(DEFAULT_EXP));
    }

    public RLock getRedisLock(String key){
        return redissonClient.getLock(key);
    }
}
